# 瀑布效果程序 Makefile

# 编译器设置
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra -O2

# 目标文件
TARGET = waterfall
TARGET_EN = waterfall_en
SOURCE = waterfall.cpp
SOURCE_EN = waterfall_en.cpp
OBJECT = waterfall.o
OBJECT_EN = waterfall_en.o

# Windows特定设置
ifeq ($(OS),Windows_NT)
    TARGET := $(TARGET).exe
    TARGET_EN := $(TARGET_EN).exe
    CXXFLAGS += -DWIN32
    # Windows可能需要额外的库
    LIBS = 
else
    # Linux/Unix设置
    LIBS = -pthread
endif

# 默认目标
all: $(TARGET) $(TARGET_EN)

# 编译可执行文件
$(TARGET): $(OBJECT)
	@echo "链接 $(TARGET)..."
	$(CXX) $(OBJECT) -o $(TARGET) $(LIBS)
	@echo "编译完成: $(TARGET)"

$(TARGET_EN): $(OBJECT_EN)
	@echo "链接 $(TARGET_EN)..."
	$(CXX) $(OBJECT_EN) -o $(TARGET_EN) $(LIBS)
	@echo "编译完成: $(TARGET_EN)"

# 编译目标文件
$(OBJECT): $(SOURCE)
	@echo "编译 $(SOURCE)..."
	$(CXX) $(CXXFLAGS) -c $(SOURCE) -o $(OBJECT)

$(OBJECT_EN): $(SOURCE_EN)
	@echo "编译 $(SOURCE_EN)..."
	$(CXX) $(CXXFLAGS) -c $(SOURCE_EN) -o $(OBJECT_EN)

# 清理编译产物
clean:
	@echo "清理编译产物..."
	rm -f $(OBJECT) $(OBJECT_EN) $(TARGET) $(TARGET_EN)
	@echo "清理完成"

# 运行程序
run: $(TARGET)
	@echo "运行瀑布效果程序..."
	./$(TARGET)

# 运行英文版本
run-en: $(TARGET_EN)
	@echo "运行英文版瀑布效果程序..."
	./$(TARGET_EN)

# 运行动态瀑布
run-dynamic: $(TARGET)
	@echo "运行动态粒子瀑布..."
	./$(TARGET) 1

# 运行动态瀑布（英文版）
run-dynamic-en: $(TARGET_EN)
	@echo "运行动态粒子瀑布（英文版）..."
	./$(TARGET_EN) 1

# 运行ASCII瀑布
run-ascii: $(TARGET)
	@echo "运行简单ASCII瀑布..."
	./$(TARGET) 2

# 运行ASCII瀑布（英文版）
run-ascii-en: $(TARGET_EN)
	@echo "运行简单ASCII瀑布（英文版）..."
	./$(TARGET_EN) 2

# 调试版本
debug: CXXFLAGS += -g -DDEBUG
debug: clean $(TARGET) $(TARGET_EN)
	@echo "调试版本编译完成"

# 发布版本
release: CXXFLAGS += -DNDEBUG -O3
release: clean $(TARGET) $(TARGET_EN)
	@echo "发布版本编译完成"

# 检查代码风格（需要cppcheck）
check:
	@echo "检查代码风格..."
	@if command -v cppcheck >/dev/null 2>&1; then \
		cppcheck --enable=all --std=c++11 $(SOURCE); \
	else \
		echo "cppcheck未安装，跳过代码检查"; \
	fi

# 安装程序到系统路径
install: $(TARGET) $(TARGET_EN)
	@echo "安装 $(TARGET) 和 $(TARGET_EN) 到 /usr/local/bin..."
	sudo cp $(TARGET) $(TARGET_EN) /usr/local/bin/
	@echo "安装完成"

# 卸载程序
uninstall:
	@echo "卸载 $(TARGET) 和 $(TARGET_EN)..."
	sudo rm -f /usr/local/bin/$(TARGET) /usr/local/bin/$(TARGET_EN)
	@echo "卸载完成"

# 创建发布包
package: release
	@echo "创建发布包..."
	mkdir -p waterfall_effect_release
	cp $(TARGET) $(TARGET_EN) README.md Makefile waterfall_effect_release/
	tar -czf waterfall_effect.tar.gz waterfall_effect_release/
	rm -rf waterfall_effect_release/
	@echo "发布包创建完成: waterfall_effect.tar.gz"

# 显示帮助信息
help:
	@echo "瀑布效果程序 Makefile"
	@echo ""
	@echo "可用目标:"
	@echo "  all            - 编译程序（默认）"
	@echo "  clean          - 清理编译产物"
	@echo "  debug          - 编译调试版本"
	@echo "  release        - 编译发布版本"
	@echo "  run            - 运行程序（中文，交互选择）"
	@echo "  run-en         - 运行程序（英文，交互选择）"
	@echo "  run-dynamic    - 运行动态粒子瀑布（中文）"
	@echo "  run-dynamic-en - 运行动态粒子瀑布（英文）"
	@echo "  run-ascii      - 运行简单ASCII瀑布（中文）"
	@echo "  run-ascii-en   - 运行简单ASCII瀑布（英文）"
	@echo "  check          - 检查代码风格"
	@echo "  install        - 安装到系统路径"
	@echo "  uninstall      - 从系统卸载"
	@echo "  package        - 创建发布包"
	@echo "  help           - 显示此帮助信息"
	@echo ""
	@echo "使用示例:"
	@echo "  make                      # 编译程序"
	@echo "  make run                  # 运行中文程序"
	@echo "  make run-en               # 运行英文程序"
	@echo "  make run-dynamic-en       # 直接运行动态瀑布（英文）"
	@echo "  make run-ascii-en         # 直接运行ASCII瀑布（英文）"
	@echo "  make debug                # 编译调试版本"
	@echo "  make clean                # 清理文件"

# 声明伪目标
.PHONY: all clean run run-en run-dynamic run-dynamic-en run-ascii run-ascii-en debug release check install uninstall package help